<?php
if (date("H") > 13) {
require_once('../scripts/db.php');
include("includes/xmlparse.php");
include("includes/functions.php");

$query = "SELECT username, postcode, area, UNIX_TIMESTAMP(lastchecked) AS lastchecked FROM papptweet  WHERE `lastchecked` < CURDATE() LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

$postcode = $row['postcode'];
$area = $row['area'];
$lastchecked = $row['lastchecked'];
$username = $row['username'];

$url = "http://www.planningalerts.com/api.php?call=postcode&postcode=".$postcode."&area_size=". $area;

$xml = xml2array(file_get_contents($url));

$items = $xml['rss']['channel']['item'];

foreach($items as $item) {

if (strtotime($item['pubDate']['value']) >= $lastchecked) {
sendDm($username, $item['title']['value'], $item['link']['value']);
} else {
break;
}

}

$query = "UPDATE papptweet SET lastchecked = CURDATE() WHERE username = '$username'";
mysql_query($query);

}
}
?>